package com.audaque.springboot.foshanupload.redis.service.impl;

import com.audaque.springboot.foshanupload.redis.anno.RedisLuaIncrRateLimiterAnno;
import com.audaque.springboot.foshanupload.redis.service.RedisIncrRateLimiterAnnoService;

import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

/**
 * @author zgb
 * @desc ...
 * @date 2021-12-26 19:45:07
 */
@Slf4j
@Service
public class RedisIncrRateLimiterAnnoServiceImpl implements RedisIncrRateLimiterAnnoService {


    @Autowired
    RedisIncrRateLimiterAnnoService redisIncrRateLimiterAnnoService;

    //代码中接口声明的是非检查型异常RuntimeException，因此会抛出 UndeclaredThrowableException异常
    @RedisLuaIncrRateLimiterAnno( name ="add",value = 1,resultYn=true)
    public Boolean add() throws Exception{
        return true;
    }
    public Boolean addResult(){
        Boolean result = false;
        try {
            result = redisIncrRateLimiterAnnoService.add();
        } catch (Exception e) {
            //并发异常或获取不到令牌
            result = false;
        }
        return result;
    }
}
